package com.yun.many.auth.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yun.many.auth.dao.entity.User;
import com.yun.many.auth.model.group.ValidGroup;
import com.yun.many.auth.model.req.UserEditReq;
import com.yun.many.auth.model.req.UserQueryReq;
import com.yun.many.auth.model.resp.UserVo;
import com.yun.many.auth.service.IUserService;
import com.yun.many.spec.vo.HttpResult;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("user")
@RequiredArgsConstructor
public class UserController extends BaseController {

    private final IUserService userService;

    @PostMapping("/page")
    public HttpResult<Page<UserVo>> pageList(UserQueryReq req) {
        Page<UserVo> userPage = userService.pageUser(req);
        return HttpResult.success(userPage);
    }

    @PostMapping("/save")
    public HttpResult<Boolean> add(@Validated UserEditReq req, BindingResult result) {
        validate(result);

        return HttpResult.success(userService.save(req));
    }

    @PostMapping("/delete")
    public HttpResult<Boolean> delete(UserQueryReq req) {
        return HttpResult.success(userService.delete(req));
    }

    @PostMapping("/frozen")
    public HttpResult<Boolean> frozen(UserQueryReq req) {
        return HttpResult.success(userService.frozen(req));
    }
}
